import librosa
from utility import collect_map,creat_hash,getscores,fix_rate,window_length_seconds,frequency_bits
import os
import pickle

if __name__ == "__main__":
    
    # 加载数据库
    database = pickle.load(open("database.pickle",'rb'))
    dic_idx2song = pickle.load(open("song_index.pickle",'rb'))
    print(database)
    # 读取歌曲
    file_record = "record.m4a"
    y,fs = librosa.load(file_record,sr=fix_rate)
    
    # 检索打分
    scores = getscores(y,fs,database)
    
    # 打印检索信息
    for k,v in scores:
        file = dic_idx2song[k]
        name = os.path.split(file)[-1]
        print('%s :  %d : %d'%(name,v[0],v[1]))


    # 打印结果
    print("检索最终结果为",os.path.split(dic_idx2song[scores[0][0]])[-1])


